// pages/tabBar/index/index.js
import tui from './../../../common/httpRequest'
let dateTime;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bgImg: ' https://image.anji-navinfo.cn/group1/M00/9F/9F/img/ic_bgIndex.png',
    topHead1: '/static/images/tx/no1.jpeg',
    topHead2: '/static/images/tx/no2.jpeg',
    topHead3: '/static/images/tx/no3.jpeg',
    top1: ' https://image.anji-navinfo.cn/group1/M00/9F/9F/img/frist_icon.png',
    top2: ' https://image.anji-navinfo.cn/group1/M00/9F/9F/img/sec_icon.png',
    top3: ' https://image.anji-navinfo.cn/group1/M00/9F/9F/img/thr_icon.png',
    ruleImg: 'http://118.178.134.62:8030/images/file/rule.png',
    name: "赵建国",
    recordsing: '-',
    recordsNow: '-',
    list: [
    ],
    listThr: [],
    result: '-',
    ifLoading: false,
    modal: false,
    text:' 1.1当月有效任务数<=4，每个任务满分25分，个人当月绩效评分等于当月各任务积分之和；',
    toprankHeight:0,
    toprankListH:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var myDate = new Date();//获取系统当前时间
    getApp().globalData.ifHide = '2'
    getApp().globalData.searchName = ''
    wx.setStorageSync('searchName', '');
    let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    let month = myDate.getMonth() + 1;
    this.setData({
      result: year + '-' + month,
      year: year,
      month: month,
      name: wx.getStorageSync('name')
    })
    this.getHeight()
    this.getList()
  },
  show: function (e) {
    dateTime && dateTime.show();
  },
  openFile() {
    // console.log('asd')
    this.setData({
      modal: true
    })
  },
  hide() {
    this.setData({
      modal: false
    })
  },
  toTask(e) {
    console.log(e.currentTarget.dataset.name)
    getApp().globalData.searchName = e.currentTarget.dataset.name
    getApp().globalData.ifHide = '2'
    wx.setStorageSync('searchName', e.currentTarget.dataset.name);
    console.log(getApp().globalData.searchName, 'getApp().globalData.searchName')
    wx.switchTab({
      url: '/pages/tabBar/task/index'
    })
    // setTimeout(()=>{
    //   wx.switchTab({
    //     url: '/pages/tabBar/task/index',
    //     success: function (e) {
    //       var page = getCurrentPages().pop();
    //       if (page == undefined || page == null) return;
    //       page.onLoad();

    //     }
    //   })
    // },500)

  },

  async getList() {
    // sys/task/userScoreRank
    const res = await tui.request('sys/task/personQuery', 'GET', {
      year: this.data.year,
      month: this.data.month,
      name: wx.getStorageSync('name'),
      departNum:wx.getStorageSync('department'),
    }, true);
    if (res.code == 20000) {
      let list = res.data.rankInfoList
      list.forEach(element => {
        element.taskScore = Number(element.taskScore).toFixed(2)
      });
      let lista = list.slice(3)

      this.setData({
        // list: list,
        recordsNow: Number(res.data.qscore).toFixed(2),
        recordsing: res.data.qtaskNum,
        list: list,
        listThr: lista
      })
      // console.log(listThr,'listThr')
    }

  },
  // 获取最新得数据
  refreshTime() {
    this.setData({
      ifLoading: true
    })
    this.getList()
    this.setData({
      ifLoading: false
    })
  },
  getHeight() {
    const capsuleInfo = wx.getMenuButtonBoundingClientRect();//胶囊信息
    const systemInfo = wx.getSystemInfoSync(); // 获取设备信息
    const statusHeight = systemInfo.statusBarHeight // 状态栏高度
    const clientHeight = systemInfo.windowHeight, clientWidth = systemInfo.windowWidth, rpxR = 750 / clientWidth;
    const calc = clientHeight * rpxR;
    console.log(systemInfo,'systemInfo',calc,clientHeight,statusHeight)
    // calc({{toprankHeight}}-env(safe-area-inset-bottom))
    // console.log(systemInfo)
    this.setData({
      winHeight: calc,
      height: capsuleInfo.height,
      statusHeight: statusHeight,
      top: (capsuleInfo.top + statusHeight) / 2,
      topD: 45 + statusHeight,
      heightPage: clientHeight - statusHeight - 45,
      infoHeight: clientHeight - statusHeight - 45 - 189 - 90,
      clientWidth: clientWidth - 20,
      heightOver: clientHeight - statusHeight - 45 - 189 - 100,
      toprankHeight:clientHeight - statusHeight - 45,
      toprankListH:clientHeight - statusHeight - 45-100-152
    })
    // console.log(capsuleInfo.top, statusHeight)
  },
  // 时间选择
  change: function (e) {
    this.setData({
      result: e.detail.result,
      year: e.detail.year,
      month: e.detail.month
    })
    this.refreshTime()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    dateTime = this.selectComponent("#dateTime")

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
console.log(getApp().globalData.ifExemine,'getApp().globalData.ifExemine')
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        current: '0',
        ['tabBar[2].num']:getApp().globalData.ifExemine
      })

    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    dateTime && dateTime.hide();
    this.setData({
      modal: false
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})